package com.band.service.impl;

import com.band.entity.PageBean;
import com.band.entity.Student;
import com.band.entity.StudentQueryParam;
import com.band.mapper.StudentMapper;
import com.band.service.StudentService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;
    /**
     * 条件分页查询
     * @param param
     * @return
     */
    @Override
    public PageBean list(StudentQueryParam param) {
        PageHelper.startPage(param.getPage(), param.getPageSize());
        List<Student> empList = studentMapper.list(param);
        Page p = (Page) empList;
        return new PageBean(p.getTotal(), p.getResult());
    }

    /**
     * 批量删除学生
     * @param ids
     */
    @Override
    public void delete(List<Integer> ids) {
        studentMapper.delete(ids);
    }

    @Override
    public void insert(Student student) {
        //1.补充基本信息
        student.setCreateTime(LocalDateTime.now());
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.insert(student);
    }

    @Override
    public Student select(Integer id) {
        return studentMapper.select(id);
    }

    @Override
    public void update(Student student) {
        //1.补充基本信息
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.update(student);
    }

    @Override
    public void violantan(Integer id, Short score) {
        studentMapper.violantan(id, score);
    }

    @Override
    public List<Map> studentDegreeData() {
        return studentMapper.studentDegreeData();
    }
}
